const app = getApp();
const imageTools = app.imageTools;

// components/changeable_img/changeable_img.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    imageNodeObject: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imageNodeObj: { }
  },
  /**
   * 生命周期
   */
  lifetimes: {
    ready: function () {
      this.setData({
        imageNodeObj: this.data.imageNodeObject
      })
    }
  },
  observers: {
    "imageNodeObject": function (imageNodeObject) {
      this.setData({
        imageNodeObj: imageNodeObject
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    imageTouchStart: function (e) {
      let that = this;
      if (e.touches.length > 1) {
        this.data.imageNodeObj = imageTools.scaleStartFn(that, "imageNodeObj", e);
      } else if (e.touches.length == 1) {
        this.data.imageNodeObj = imageTools.dragStartFn(that, "imageNodeObj", e);
      } else {
        return false;
      }
    },
    imageTouchMove: function (e) {
      let that = this;
      let imageNode;
      if (e.touches.length > 1) {
        imageNode = imageTools.scaleMoveFn(that, "imageNodeObj", e);
      } else if (e.touches.length == 1) {
        imageNode = imageTools.dragMoveFn(that, "imageNodeObj", e);
      } else {
        return false;
      }

      this.setData({ //赋值就移动了  
        imageNodeObj: imageNode
      })
    },
    imageTouchEnd: function (e) {
      let that = this;
      let imageNode = imageTools.touchEnd(that, "imageNodeObj", e);
      that.data.imageNodeObj = imageNode;
    } 
  }
})
